package com.yodawnla.fishing;

import java.util.ArrayList;

import com.yodawnla.fishing.system.Save;
import com.yodawnla.lib.YoActivity;
import com.yodawnla.lib.util.save.YoSaveFile;
import com.yodawnla.lib.util.save.YoSaveManager;

public class FishRec
{
	int mFishID;
	int mMaxSize;
//	String mName;
	int mTotalHitCount;
	ArrayList<Integer> mUsedBaitList = new ArrayList<Integer>(); 
	
	YoSaveFile mSaveFile = YoSaveManager.getInstance().getSaveFile(Save.FileName.DB);
	
	public FishRec(int fishID, String saveData)
	{
		mFishID = fishID;
		if (saveData.equals(""))
			return;
		
		// totalHit!maxSize!baitType#baitType...
		String[] data = saveData.split("!");
		mTotalHitCount = Integer.valueOf(data[0]);
		mMaxSize = Integer.valueOf(data[1]);
		
		String[] baitTypes = data[2].split("#");
		for (int i = 0 ; i < baitTypes.length ; ++i)
		{
			if (baitTypes[i].equals(""))
				break;
			
			mUsedBaitList.add(Integer.valueOf(baitTypes[i]));
		}
		 
			 
		 
	}
	
	public FishRec(int fishID)
	{
		mFishID = fishID;
	}
	
	public void recFish(Fish fish)
	{
		setMaxSize(fish.getLength());
		addHitCount();
	}
	
	public void setMaxSize(int maxSize)
	{
		if (maxSize > mMaxSize)
		{
			mMaxSize = maxSize;
		}
	}
	
	public void addHitCount()
	{
		++mTotalHitCount;
	}
	
	public int getHitCount()
	{
		return mTotalHitCount;
	}
	
	public void addUsedBait(FishBait bait)
	{
		int type = bait.getFishbaitType();
		boolean inList = false;
		for (int i = 0 ; i < mUsedBaitList.size() ; ++i)
		{
			if (type == mUsedBaitList.get(i))
			{
				inList = true;
				break;
			}
		}
		
		if (!inList)
			mUsedBaitList.add(type);
	}
	
 
	
	public ArrayList<Integer> getUsedBaitList()
	{
		return mUsedBaitList;
	}
 
	public int getFishId()
	{
		return mFishID;
	}
	
	public void save()
	{
		// totalHit!maxSize!baitType#baitType...
		String saveString = mTotalHitCount+"!"+mMaxSize+"!";
		for (int i = 0 ; i < mUsedBaitList.size() ; ++i)
		{
			saveString += mUsedBaitList.get(i)+"#";
		}
		 
		
		mSaveFile.setString(Save.DB.Fish+mFishID, saveString);
		mSaveFile.save();
		
	}
	
//	public void setFishName(String name)
//	{
//		mName=name;
//	}
//	
	public String getFishName()
	{
		return YoActivity.getBaseActivity().getRString(R.string.fish1+mFishID);
	}
	
	public int getFishMaxLength()
	{
		return mMaxSize;
	}
	 
 
}
